const citys = require('../data/city.json');
const utils = require('../assest/utils');

const setData = (citys = []) => {
  citys.forEach(c => {
    c.city = c.name;
    c.cases = utils.randomNum(0, 50);
    c.healthcare = utils.randomNum(0, 50);
    c.deaths = utils.randomNum(0, 50);
    c.wearMask = utils.randomNum(0, 50) % 2 ? 'Y' : 'N';
    c.restrictiveMeasures = 'lorem 1111 ...';
    c.value = c.cases / 1 + c.healthcare / 1 + c.deaths / 1;
  });
  return citys;
};

let citylist = setData(citys);

const search = (citylist, val) => {
  let result = [];
  citylist.forEach(item => {
    if (item.city.includes(val)) {
      result.push(item);
    }
  });
  return result;
};

const getWholeCovidStatus = (val = '') => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve(search(citylist, val));
    }, 1000);
  });
};

module.exports = getWholeCovidStatus;